<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">我发布的</h1>
		</header>
		<div class="mui-content" id="goods_list">
			<div class="mui-card" v-for="goods in list">
				<div class="mui-card-content">
					<img :src="goodsImgPath+goods.pictureArray[0]" style="width: 80px;height: 80px;float: left;padding: 10px;" />
					<div style="float: left;padding-top: 10px;">
						<div style="height: 70%;width: 200px;">{{goods.des}}</div>
						<p>{{goods.campus}}&middot;
							<span v-if="goods.sellStatus ==30" style="margin-left: 10px;">【在售】</span>
							<span v-if="goods.sellStatus ==31" style="margin-left: 10px;">【已售出】</span>
						</p>
					</div>
				</div>
				<div class="mui-card-footer" style="clear: both;">
					<span>{{goods.createTimeText}}</span>
					<button @click="delete_goods(goods.id)">删除</button>
				</div>
			</div>

		</div>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/vue.min.js"></script>
		<script type="text/javascript" src="../js/const.js"></script>
		<script type="text/javascript" src="../js/request.js"></script>
		<script type="text/javascript" src="../js/goods_service.js"></script>
		<script type="text/javascript">
			mui.init()

			var goods_list = new Vue({
				el: '#goods_list',
				data: {
					list: [],
					goodsImgPath: GOODS_IMG_PATH + '/',
					userFacePath: USER_FACE_PATH + '/'
				},
				methods: {
					//打开详情页面
					open_detail: function(id) {
						//触发详情页面的自定义事件
						mui.fire(detailPage, 'goodsId', {
							id: id
						});
						detailPage.show('slide-in-right');
					},
					delete_goods: function(id) {

						var btnArray = ['取消', '确定'];
						mui.confirm('你真的忍心删除我？', '提示', btnArray, function(e) {
							if(e.index == 1) {
								var res = goodsService.delete_goods(id);
								plus.nativeUI.toast(res.msg);
								if(res.resultCode == REQUEST_SUCCESS_CDOE) {
									var res = goodsService.find_good_list();
									goods_list.list = res.data;
								}
							}
						})

					}
				}
			});

			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				//添加hide事件
				self.addEventListener('hide', function(e) {
					window.scrollTo(0, 0); //滚到顶部
					data_detail.resetData(); //数据重置
				}, false);
				plus.nativeUI.showWaiting('加载中', {
					width: '100px',
					height: '100px'
				});
				//获取接口数据
				var res = goodsService.find_good_list();
				goods_list.list = res.data;
				plus.nativeUI.closeWaiting();
				//给detailPage赋值,根据ID获取详情页面
				detailPage = plus.webview.getWebviewById('goods-detail');
				if(!detailPage) {
					detailPage = mui.preload({
						id: 'goods-detail',
						url: 'html/goods_detail.html'
					});
				}

			});
		</script>
	</body>

</html>